{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bdbe13fc",
   "metadata": {},
   "source": [
    "# lesson 1\n",
    "\n",
    "## class 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1164a75f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:02:00.301408Z",
     "start_time": "2022-03-03T06:02:00.286449Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3663c6bd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:42:18.473585Z",
     "start_time": "2022-03-03T06:42:18.455634Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def h(a,b):\n",
    "    '''\n",
    "    @description: use to do summation\n",
    "    @param: two inputs\n",
    "    '''\n",
    "    # sum\n",
    "    c = a+b \n",
    "    return c # 返回结果\n",
    "\n",
    "\n",
    "def h(a,b):\n",
    "    pass\n",
    "\n",
    "h(1,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9964c755",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:47:57.513608Z",
     "start_time": "2022-03-03T06:47:57.494664Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "good\n",
      "good\n",
      "good\n",
      "1\n",
      "good\n",
      "1\n",
      "good\n",
      "1\n",
      "good\n",
      "good\n",
      "1\n",
      "good\n",
      "1\n",
      "good\n",
      "good\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "grade = np.random.randint(50,101,10)\n",
    "\n",
    "for i in grade:\n",
    "    if i >80:\n",
    "        print('1')\n",
    "    print('good')\n",
    " \n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "eef48ea5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:49:41.825901Z",
     "start_time": "2022-03-03T06:49:35.631086Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what's your name?may\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'may'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# input()  & print\n",
    "\n",
    "input(\"what's your name?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0f86cf34",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:51:20.985602Z",
     "start_time": "2022-03-03T06:51:20.963149Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World!\n"
     ]
    }
   ],
   "source": [
    "print('Hello World!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e2f4e570",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:53:53.588835Z",
     "start_time": "2022-03-03T06:53:53.567892Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 + 2\n"
     ]
    }
   ],
   "source": [
    "a = 1\n",
    "b = 2\n",
    "c = 3\n",
    "print(a, end=\" + \")\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "11a02ec7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:57:17.682619Z",
     "start_time": "2022-03-03T06:57:17.663672Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(345, 123)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = 345\n",
    "NAME = 123\n",
    "\n",
    "name, NAME"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "f0d4977d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:00:45.365469Z",
     "start_time": "2022-03-03T06:59:47.021177Z"
    },
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Welcome to Python 3.9's help utility!\n",
      "\n",
      "If this is your first time using Python, you should definitely check out\n",
      "the tutorial on the Internet at https://docs.python.org/3.9/tutorial/.\n",
      "\n",
      "Enter the name of any module, keyword, or topic to get help on writing\n",
      "Python programs and using Python modules.  To quit this help utility and\n",
      "return to the interpreter, just type \"quit\".\n",
      "\n",
      "To get a list of available modules, keywords, symbols, or topics, type\n",
      "\"modules\", \"keywords\", \"symbols\", or \"topics\".  Each module also comes\n",
      "with a one-line summary of what it does; to list the modules whose name\n",
      "or summary contain a given string such as \"spam\", type \"modules spam\".\n",
      "\n",
      "help> keywords\n",
      "\n",
      "Here is a list of the Python keywords.  Enter any keyword to get more help.\n",
      "\n",
      "False               break               for                 not\n",
      "None                class               from                or\n",
      "True                continue            global              pass\n",
      "__peg_parser__      def                 if                  raise\n",
      "and                 del                 import              return\n",
      "as                  elif                in                  try\n",
      "assert              else                is                  while\n",
      "async               except              lambda              with\n",
      "await               finally             nonlocal            yield\n",
      "\n",
      "\n",
      "You are now leaving help and returning to the Python interpreter.\n",
      "If you want to ask for help on a particular object directly from the\n",
      "interpreter, you can type \"help(object)\".  Executing \"help('string')\"\n",
      "has the same effect as typing a particular string at the help> prompt.\n"
     ]
    }
   ],
   "source": [
    "help()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "02b08c33",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:00:45.938667Z",
     "start_time": "2022-03-03T07:00:45.873846Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [10,20,30,40,\\\n",
    "50,60,70,\\\n",
    "80,90,100]\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1bd61b52",
   "metadata": {},
   "source": [
    "##  六个标准的数据类型\n",
    "\n",
    "Number (数字)\n",
    "\n",
    "int\n",
    "\n",
    "bool\n",
    "\n",
    "float\n",
    "\n",
    "complex （复数）\n",
    "\n",
    "String （字符串）\n",
    "\n",
    "List （列表）\n",
    "\n",
    "Tuple （元组）\n",
    "\n",
    "Sets\n",
    "\n",
    "Dictionary\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7478cde1",
   "metadata": {},
   "source": [
    "### NUMBER"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9430a397",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:18:21.954036Z",
     "start_time": "2022-03-03T07:18:21.933092Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "hey\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(int, str)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a , b = 1, 'hey'\n",
    "print(a)\n",
    "print(b)\n",
    "type(a),type(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "696635cc",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:19:56.562740Z",
     "start_time": "2022-03-03T07:19:56.543789Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(float, True)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# float\n",
    "f = 1.28787\n",
    "type(f), isinstance(f,float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "263757ff",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:20:32.376545Z",
     "start_time": "2022-03-03T07:20:32.355607Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "bool"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# bool\n",
    "b = True\n",
    "type(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "8d4a2232",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:20:58.831633Z",
     "start_time": "2022-03-03T07:20:58.814666Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1+1j)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "complex"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# complex\n",
    "c = 1+1j\n",
    "print(c)\n",
    "type(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "39e88874",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:21:59.588363Z",
     "start_time": "2022-03-03T07:21:59.566425Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0b1000'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bin(8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "f9b84a3e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:25:26.348302Z",
     "start_time": "2022-03-03T07:25:26.332340Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what's your name\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# string\n",
    "\n",
    "a = '123'\n",
    "type(a)\n",
    "a = \"what's your name\"\n",
    "print(a)\n",
    "type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "8d52730a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:27:10.034440Z",
     "start_time": "2022-03-03T07:27:10.008509Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what\\'s your name\n",
      "hey \n",
      " hey\n"
     ]
    }
   ],
   "source": [
    "a = r'what\\'s your name'\n",
    "print(a)\n",
    "a = 'hey \\\\n hey'\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "d177a377",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:28:05.319934Z",
     "start_time": "2022-03-03T07:28:05.303977Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hey \\\\n hey\n"
     ]
    }
   ],
   "source": [
    "a = r'hey \\\\n hey'\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "90d2aa69",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:33:56.560933Z",
     "start_time": "2022-03-03T07:33:56.538991Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ade-name-ema'"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 'grade-name-email'\n",
    "\n",
    "a[0:3] # 首包括，尾不包括\n",
    "a[-1::-1]\n",
    "a[2:-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "cadd9108",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:32:42.434787Z",
     "start_time": "2022-03-03T07:32:42.423813Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'gaenm-mi'"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[::2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "e4b133eb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:36:04.086390Z",
     "start_time": "2022-03-03T07:36:04.060461Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hey\n",
      "----------\n",
      "next round\n",
      "you\n"
     ]
    }
   ],
   "source": [
    "a = 'hey'\n",
    "b ='you'\n",
    "a*3\n",
    "print(a)\n",
    "print('-'*10)\n",
    "print('next round:')\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aee03556",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:36:32.012039Z",
     "start_time": "2022-03-03T07:36:31.990100Z"
    }
   },
   "source": [
    "# 列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "20f381c2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:38:02.194095Z",
     "start_time": "2022-03-03T07:38:02.171156Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls = [1,2,3,'jiji',True]\n",
    "type(ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "0119e4c8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:39:17.418360Z",
     "start_time": "2022-03-03T07:39:17.391433Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 'jiji', True]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# slice\n",
    "ls[2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "16357725",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:40:00.894860Z",
     "start_time": "2022-03-03T07:40:00.878900Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[True, 'jiji', 3, 2, 1]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls[-1::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "a01fb210",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:41:19.347152Z",
     "start_time": "2022-03-03T07:41:19.334185Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 4, 3, 2, 1]"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls= [1,2,3,4,5]\n",
    "ls.reverse()\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "6af4721e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:43:57.296721Z",
     "start_time": "2022-03-03T07:43:57.273785Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 4, 3, 'good', 1]"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls[3] = 'good'\n",
    "ls"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "092dfd10",
   "metadata": {},
   "source": [
    "### 列表的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "e65f78ce",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:46:19.904812Z",
     "start_time": "2022-03-03T07:46:19.888802Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 4, 3, 'good', 1, 10, [10, 20, '%store']]\n",
      "[5, 4, 3, 'good', 1, 10, [10, 20, '%store'], 10]\n"
     ]
    }
   ],
   "source": [
    "# append: 在list后面加入一个变量\n",
    "print(ls)\n",
    "ls.append(10)\n",
    "print(ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "f2d26e5e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:48:37.657233Z",
     "start_time": "2022-03-03T07:48:37.636289Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, [10, 20, '%store']]\n",
      "----------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, [10, 20, '%store'], 10, 20, 30]"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls = [1,2,3]\n",
    "ls.append([10,20,'%store'])\n",
    "print(ls)\n",
    "print('-'*10)\n",
    "ls.extend([10,20,30])\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "8b2a5bee",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:50:17.073080Z",
     "start_time": "2022-03-03T07:50:17.063106Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 长度   len()\n",
    "len(ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "a58d6ba8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:51:55.878095Z",
     "start_time": "2022-03-03T07:51:55.854162Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 'hello', 'hello', [10, 20, '%store'], 10, 20, 30]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 'hello', 'hello', 'hello', [10, 20, '%store'], 10, 20, 30]"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 添加变量\n",
    "# ls.insert(position, var)\n",
    "print(ls)\n",
    "ls.insert(3,'hello')\n",
    "ls\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "61ae9e09",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:53:00.200744Z",
     "start_time": "2022-03-03T07:53:00.178802Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算var出现的次数\n",
    "ls.count('hello')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "218dcbad",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:55:07.058986Z",
     "start_time": "2022-03-03T07:55:07.040026Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['hello', 'hello', 'hello', [10, 20, '%store'], 10, 20, 30]\n",
      "hello\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['hello', 'hello', [10, 20, '%store'], 10, 20, 30]"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ls.pop(index)  弹出相应位置的变量\n",
    "print(ls)\n",
    "a = ls.pop(0)\n",
    "print(a)\n",
    "ls\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "a86f217b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:56:19.426139Z",
     "start_time": "2022-03-03T07:56:19.390237Z"
    }
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "list.remove(x): x not in list",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_17316/943293614.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# ls.remove(var)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'hello'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0mls\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: list.remove(x): x not in list"
     ]
    }
   ],
   "source": [
    "# ls.remove(var)\n",
    "ls.remove('hello')\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "9a574af4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:59:05.076966Z",
     "start_time": "2022-03-03T07:59:05.061020Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[60, 10, 7, 4, 3, 2, 1]"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ls.sort()  默认是升序, reverse = True; \n",
    "\n",
    "ls = [1,2,3,10,4,7,60]\n",
    "ls.sort(reverse = True)\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "f85a2496",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:59:50.916091Z",
     "start_time": "2022-03-03T07:59:50.895151Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[60, 10, 7, 4, 3, 2, 1]\n",
      "[60, 10, 7, 4, 3, 2, 1]\n"
     ]
    }
   ],
   "source": [
    "# copy \n",
    "\n",
    "ls2 = ls\n",
    "print(ls2)\n",
    "ls3 = ls.copy()\n",
    "print(ls3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d36d7a50",
   "metadata": {},
   "source": [
    "## Class 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8518b57e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T05:59:08.603899Z",
     "start_time": "2022-03-10T05:59:08.593735Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'goodday'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = '  good day  '\n",
    "b = a.strip().replace(' ','')\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "03804728",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:09:29.446405Z",
     "start_time": "2022-03-10T06:09:29.426788Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# list 查找\n",
    "\n",
    "ls = [1,2,3,4,5]\n",
    "10 not in ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "739f819b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:08:35.398321Z",
     "start_time": "2022-03-10T06:08:35.381189Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls.clear()\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "069346dd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:09:43.494546Z",
     "start_time": "2022-03-10T06:09:43.474741Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4, 5]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del ls[0]\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5f0b3c67",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:12:26.394860Z",
     "start_time": "2022-03-10T06:12:26.383482Z"
    }
   },
   "outputs": [],
   "source": [
    "# sort  NOTE only number sort\n",
    "ls2 = ['a','A']\n",
    "a = ls2.sort()\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f450e5ee",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:27:42.617065Z",
     "start_time": "2022-03-10T06:27:42.593264Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b: [1, 2, 3, 4, 5]\n",
      "c: [1, 2, 3, 4, 5]\n",
      "True True True\n",
      "[10, 20]\n",
      "[1, 2, 3, 4, 5]\n"
     ]
    }
   ],
   "source": [
    "## 复制列表\n",
    "\n",
    "a = [1,2,3,4,5]\n",
    "\n",
    "b = a\n",
    "\n",
    "c = a.copy()\n",
    "\n",
    "print('b:',b)\n",
    "print('c:', c)\n",
    "print(b == a, c ==a, b == c )\n",
    "\n",
    "b =[10,20]\n",
    "print(b)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7891c6a0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:22:23.705263Z",
     "start_time": "2022-03-10T06:22:23.684954Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(True, False, False)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id(a) == id(b), id(a)== id(c), id(b) == id(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b41ded15",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:25:17.029645Z",
     "start_time": "2022-03-10T06:25:17.012724Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 2, 3, 4, 5]\n",
      "[0, 2, 3, 4, 5]\n",
      "----------\n",
      "[100, 2, 3, 4, 5]\n",
      "[0, 2, 3, 4, 5]\n"
     ]
    }
   ],
   "source": [
    "b[0] = 0\n",
    "print(b)\n",
    "print(a)\n",
    "print('-'*10)\n",
    "c[0] = 100\n",
    "print(c)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "67ae0b57",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:26:57.699742Z",
     "start_time": "2022-03-10T06:26:57.692297Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "a  = 1\n",
    "b = a\n",
    "\n",
    "b = 10\n",
    "print(b)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "3e5d55fa",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:29:33.805695Z",
     "start_time": "2022-03-10T06:29:33.770640Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   name  age\n",
      "0     1   10\n",
      "1     2   20\n",
      "2     3   30\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df = pd.DataFrame({'name':[1,2,3],'age':[10,20,30]})\n",
    "print(df)\n",
    "df2 = df  # 慎用 = 复制变量\n",
    "df2 is df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ecc515d",
   "metadata": {},
   "source": [
    "## tuple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c60d2d5f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:32:57.904285Z",
     "start_time": "2022-03-10T06:32:57.883495Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = (1,'jiji',[1,2,3],10)\n",
    "type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "f5ad143b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:33:42.806699Z",
     "start_time": "2022-03-10T06:33:42.790918Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('jiji', [1, 2, 3])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[1:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "10602caf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:34:49.834465Z",
     "start_time": "2022-03-10T06:34:49.819506Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, 3, 1, 2, 3)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(1,2,3)*2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "c1f8f9d3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:35:36.097126Z",
     "start_time": "2022-03-10T06:35:36.083553Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1,)\n"
     ]
    }
   ],
   "source": [
    "a = (1,)\n",
    "type(a)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "8f2c7ec1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:37:14.422077Z",
     "start_time": "2022-03-10T06:37:14.402033Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, 3, ['str', 5, 6])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = (1,2,3,[4,5,6])\n",
    "a[3][0] = 'str'\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7a1179b",
   "metadata": {},
   "source": [
    "## Set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "d2658e32",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:40:55.602401Z",
     "start_time": "2022-03-10T06:40:55.588508Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list2 = [1,2,3,3,3,3]\n",
    "list(set(list2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "2e98d3be",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:42:37.816566Z",
     "start_time": "2022-03-10T06:42:37.785982Z"
    }
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'set' object is not subscriptable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_6868/2514932831.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mset\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlist2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: 'set' object is not subscriptable"
     ]
    }
   ],
   "source": [
    "a = set(list2)\n",
    "a[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "fa2631cf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:48:43.699200Z",
     "start_time": "2022-03-10T06:48:43.684241Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 10, 12, 2, 3, '5'}"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.add('5')\n",
    "a.update([10,12])\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a74f5ff5",
   "metadata": {},
   "source": [
    "## 字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "08617cdf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:49:52.056533Z",
     "start_time": "2022-03-10T06:49:52.038581Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'may', 'age': 18, 'sex': 'male'}"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict1 = {'name': 'may', 'age': 18, 'sex':'male'}\n",
    "dict1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "699f6a90",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:57:40.669376Z",
     "start_time": "2022-03-10T06:57:40.649429Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': ['may', 'kate', '小王'], 'age': 18, 'sex': 'male', 'emal': 'xiaozhang@163.com'}\n",
      "{'name': ['may', 'kate', '小王'], 'age': 18, 'sex': 'male', 'emal': 'xiaozhang@163.com', 'height': 170, 'weight': 100}\n",
      "('weight', 100)\n",
      "{'name': ['may', 'kate', '小王'], 'age': 18, 'sex': 'male', 'emal': 'xiaozhang@163.com', 'height': 170}\n"
     ]
    }
   ],
   "source": [
    "dict1 = {'name': ['may','kate','小王'], 'age': 18, 'sex':'male'}\n",
    "dict1['emal'] = 'xiaozhang@163.com'\n",
    "print(dict1)\n",
    "dict1.update({'height': 170, 'weight':100})\n",
    "print(dict1)\n",
    "# popitem\n",
    "print(dict1.popitem())\n",
    "print(dict1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "40b1d359",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:58:18.889317Z",
     "start_time": "2022-03-10T06:58:18.868373Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(dict1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "a1f0cb2e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:00:56.379761Z",
     "start_time": "2022-03-10T07:00:56.355844Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['may', 'kate', '小王'], 18, 'male', 'xiaozhang@163.com', 170]\n",
      "('age', 18)\n"
     ]
    }
   ],
   "source": [
    "list(dict1.keys())\n",
    "# values\n",
    "print(list(dict1.values()))\n",
    "# items\n",
    "print(list(dict1.items())[1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "255566a0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:05:44.160486Z",
     "start_time": "2022-03-10T07:05:44.138544Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': ['may', 'kate', '小王'], 'age': 18, 'sex': 'male', 'hey': 10}"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict1 = {'name': ['may','kate','小王'], 'age': 18, 'sex':'male'}\n",
    "dict1['hey'] = dict1.get('hey',10)\n",
    "dict1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "fa216457",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:08:03.663350Z",
     "start_time": "2022-03-10T07:08:03.644394Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "My father was a self-taught mandolin player. He was one of the best string instrument players in our town. He could not read music, but if he heard a tune a few times, he could play it. When he was younger, he was a member of a small country music\n"
     ]
    }
   ],
   "source": [
    "# 练习：计算词频\n",
    "\n",
    "sen = sen = 'My father was a self-taught mandolin player. He was one of the best string instrument players in our town. He could not read music, but if he heard a tune a few times, he could play it. When he was younger, he was a member of a small country music'\n",
    "print(sen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "51019680",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:39:54.677435Z",
     "start_time": "2022-03-10T07:39:54.653502Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'My': 1,\n",
       " 'father': 1,\n",
       " 'was': 4,\n",
       " 'a': 5,\n",
       " 'self-taught': 1,\n",
       " 'mandolin': 1,\n",
       " 'player': 1,\n",
       " 'He': 2,\n",
       " 'one': 1,\n",
       " 'of': 2,\n",
       " 'the': 1,\n",
       " 'best': 1,\n",
       " 'string': 1,\n",
       " 'instrument': 1,\n",
       " 'players': 1,\n",
       " 'in': 1,\n",
       " 'our': 1,\n",
       " 'town': 1,\n",
       " 'could': 2,\n",
       " 'not': 1,\n",
       " 'read': 1,\n",
       " 'music': 2,\n",
       " 'but': 1,\n",
       " 'if': 1,\n",
       " 'he': 4,\n",
       " 'heard': 1,\n",
       " 'tune': 1,\n",
       " 'few': 1,\n",
       " 'times': 1,\n",
       " 'play': 1,\n",
       " 'it': 1,\n",
       " 'When': 1,\n",
       " 'younger': 1,\n",
       " 'member': 1,\n",
       " 'small': 1,\n",
       " 'country': 1}"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "words_count = {}\n",
    "jishu = 1\n",
    "# for words in sen:\n",
    "#     print('round: ', jishu)\n",
    "#     print('words:', words)\n",
    "#     print('-'*10)\n",
    "#     jishu = jishu + 1\n",
    "\n",
    "for words in sen.replace('.','').replace(',','').split(' '):\n",
    "#     print('round: ', jishu)\n",
    "#     print('words:', words)\n",
    "#     print('-'*10)\n",
    "#     jishu = jishu + 1\n",
    "    words_count[words] = words_count.get(words, 0)+ 1 \n",
    "words_count\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "88e4fea6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:41:49.178975Z",
     "start_time": "2022-03-10T07:41:49.160026Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'a': 'b', 'c': 'd'}\n"
     ]
    }
   ],
   "source": [
    "a=[('a','b'),('c','d')]\n",
    "b=dict(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "a50c761a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:39:13.824428Z",
     "start_time": "2022-03-10T07:39:13.788520Z"
    }
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unbound method dict.get() needs an argument",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_6868/934030674.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mhelp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdict\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: unbound method dict.get() needs an argument"
     ]
    }
   ],
   "source": [
    "help(dict.get()\\)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "18d3c957",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:42:59.980920Z",
     "start_time": "2022-03-10T07:42:59.933051Z"
    }
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "invalid literal for int() with base 10: '1a23'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_6868/3334936319.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'1a23'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: '1a23'"
     ]
    }
   ],
   "source": [
    "a = '1a23'\n",
    "a = int(a)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "f76b5bf7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:43:32.548933Z",
     "start_time": "2022-03-10T07:43:32.532976Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval('1+1')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "785d6224",
   "metadata": {},
   "source": [
    "## 算数运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "85d50b2a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:46:24.888907Z",
     "start_time": "2022-03-10T07:46:24.872949Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(579, -333, 56088, 0.26973684210526316, 87, 3)"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 123\n",
    "b = 456\n",
    "a+b, a-b, a*b, a/b, b % a, b//a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "f839ab42",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:46:57.851496Z",
     "start_time": "2022-03-10T07:46:57.826571Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 10 \n",
    "a**3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "f08dfdd7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:47:34.991125Z",
     "start_time": "2022-03-10T07:47:34.969186Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "579"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = '123'\n",
    "int(a)+b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "id": "65aef619",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:50:26.251487Z",
     "start_time": "2022-03-10T07:50:26.228538Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 1 \n",
    "a /= 5  #  a = a/5\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7049d05f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:54:44.459235Z",
     "start_time": "2022-03-10T07:54:44.440286Z"
    }
   },
   "source": [
    "# if not 0:\n",
    "    print('hey')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "b91c3dfa",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:56:18.413736Z",
     "start_time": "2022-03-10T07:56:18.403693Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0 or 10 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8fd478ad",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T05:48:58.901952Z",
     "start_time": "2022-03-17T05:48:58.883057Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "today is Monday. \n"
     ]
    }
   ],
   "source": [
    "weekday = 'Monday. '\n",
    "sen = 'today is %s' % weekday\n",
    "print(sen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6bdd0f64",
   "metadata": {},
   "outputs": [],
   "source": [
    "sen = 'XXXXX:', a, 'XXX:', b \n",
    "print(sen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c2f8c123",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T05:49:45.032440Z",
     "start_time": "2022-03-17T05:49:45.014107Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:june, age:20\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print('name:%s, age:%d' % ('june',20))\n",
    "# s:str, d:int，f：float"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f2b78a82",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T05:52:37.148774Z",
     "start_time": "2022-03-17T05:52:37.130772Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "today s Fri, tmr is Monday. \n"
     ]
    }
   ],
   "source": [
    "weekday2 = 'Fri'\n",
    "sen = 'today s {1}, tmr is {0}'.format(weekday,weekday2)\n",
    "print(sen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a39f601b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T05:54:09.015928Z",
     "start_time": "2022-03-17T05:54:09.004642Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "M0:190,M1:60,M2:7\n"
     ]
    }
   ],
   "source": [
    "# 传入list\n",
    "m=[7,60,190]\n",
    "print('M0:{0[2]},M1:{0[1]},M2:{0[0]}'.format(m))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "054eec74",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 传入dictionary\n",
    "m2={'m0':7,'m1':60,'m2':190}\n",
    "print('M0:{m[m0]},M1:{m[m1]},M2:{m[m2]}'.format(m=m2))\n",
    "print('M0:{0[m0]},M1:{0[m1]},M2:{0[m2]}'.format(m2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "46be51c2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T05:59:14.247058Z",
     "start_time": "2022-03-17T05:59:14.229794Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "start\n",
      "选择性语句的执行\n",
      "end\n"
     ]
    }
   ],
   "source": [
    "print('start')\n",
    "if True:\n",
    "    print('选择性语句的执行')\n",
    "print('end')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "dd7f1851",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T06:03:18.452063Z",
     "start_time": "2022-03-17T06:03:16.193577Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what's your grade?30\n",
      "不及格\n"
     ]
    }
   ],
   "source": [
    "grade = input(\"what's your grade?\")\n",
    "if int(grade) >= 60:\n",
    "    print('及格')\n",
    "else:\n",
    "    print('不及格')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "e9b3f411",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T06:06:25.576038Z",
     "start_time": "2022-03-17T06:06:24.306855Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what's your grade?\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "invalid literal for int() with base 10: ''",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m--------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                   Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_15424/1140636678.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mgrade\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"what's your grade?\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgrade\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>=\u001b[0m \u001b[1;36m85\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'优秀'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgrade\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>=\u001b[0m \u001b[1;36m75\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'良好'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: ''"
     ]
    }
   ],
   "source": [
    "grade = input(\"what's your grade?\")\n",
    "if int(grade) >= 85:\n",
    "    print('优秀')\n",
    "elif int(grade) >= 75:\n",
    "    print('良好')\n",
    "elif int(grade) >= 60:\n",
    "    print('及格')\n",
    "else:\n",
    "    print('不及格')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2e071ab2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 一本书中的例子\n",
    "grade = int(input('输入成绩：'))\n",
    "\n",
    "if grade >= 60:\n",
    "    print('jige')\n",
    "elif grade >=70:\n",
    "    print('良好')\n",
    "elif grade >=85:\n",
    "    print('youxiu')\n",
    "else:\n",
    "    print('不及格')\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "26b7453e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T06:14:47.268686Z",
     "start_time": "2022-03-17T06:14:47.252996Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99  "
     ]
    }
   ],
   "source": [
    "num  = 1\n",
    "while num>0:\n",
    "    print(num, end ='  ')\n",
    "    num += 1  # num = num - 1\n",
    "    if num == 100:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "7091ae0d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T06:17:07.540931Z",
     "start_time": "2022-03-17T06:17:07.530995Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1; 4; 9; 16; 36; "
     ]
    }
   ],
   "source": [
    "# 遍历列表\n",
    "a=[1,2,3,4,6]\n",
    "for i in a:\n",
    "    print(i*i,end='; ')\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e01feec",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "713de04a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e1ea8f1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "position": {
    "height": "144.85px",
    "left": "654px",
    "right": "20px",
    "top": "122px",
    "width": "350px"
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
